<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>统计字符串中某个子串的出现次数</title>
</head>
<body>
<script>
    var myString = 'Welcome to Wrox books. ' +
            'The Wrox website is www.wrox.com. ' +
            'Visit the Wrox website today. ' +
            'Thanks for buying Wrox';
    var foundAtPosition = 0;
    var wroxCount = 0;
    while (foundAtPosition != -1) {
        foundAtPosition = myString.indexOf('Wrox', foundAtPosition);
        if (foundAtPosition != -1) {
            wroxCount++;
            foundAtPosition++;
        }
    }
    document.write('There are ' + wroxCount + ' occurrences of the word Wrox');
</script>
</body>
</html>